home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Networking / OTPAPSampleServer / PAPServerSample.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  10.2 KB  |  283 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        PAPServerSample.h
  3.  
  4.     Contains:    headers, defines for the PAPServerSample.c file
  5.  
  6.     Written by:    Rich Kubota
  7.  
  8.     Copyright:    © 1993-1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.     To Do:
  13.  
  14. */
  15.  
  16. #ifndef __PAPSERVERSAMPLE__
  17. #define __PAPSERVERSAMPLE__
  18.  
  19.  
  20. #ifndef __CONDITIONALMACROS__
  21. #include <ConditionalMacros.h>
  22. #endif
  23.  
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27.  
  28. #if PRAGMA_ALIGN_SUPPORTED
  29. #pragma options align=mac68k
  30. #endif
  31.  
  32. #if PRAGMA_IMPORT_SUPPORTED
  33. #pragma import on
  34. #endif
  35.  
  36. #include <stdio.h>
  37. #include <Types.h>
  38. #include <Memory.h>
  39. #include <Resources.h>
  40. #include <Events.h>
  41. #include "OpenTransport.h"        // open transport files    
  42. #include "OpenTptAppleTalk.h"    
  43.  
  44. //#define SHOW_DEBUG_FLOW        1    // enable display of DebugStr showing program flow
  45.  
  46. #if SHOW_DEBUG_FLOW
  47. #define    DO_DEBUG_LOG        0    // enable a debug log at the beginning
  48. #endif
  49.  
  50. // defines for the STR# resource
  51. #define kServerStrID    1000    // STR# resource ID for the PAP Server Sample strings
  52.  
  53. #define kOTVersion111    0x01118000
  54. #define kOTVersion120    0x01208000
  55.  
  56. enum {
  57.     kServerNBPStrID    = 1,
  58.     kIdleStrID,
  59.     kBusyStrID,
  60.     kForceClose = 'clos'
  61. };
  62.  
  63. #define kZeroQLen        0
  64. #define kDynamicSocket    0
  65. #define kATPType        3
  66. #define TIMEOUT            25         // seconds
  67. #define kMaxHandoffEPs    1        // maximum number of handoff endpoints supported by this sample
  68.  
  69. #define kDITop            0x0050        /* kTopLeft - for positioning the Disk
  70.                                                Initialization dialogs. */
  71. #define kDILeft            0x0070
  72.  
  73. #define kNumBuffers        25        // initial number of packet buffers to allocate
  74. #define kUserByteSize    4
  75. #define    kPAPDataSize    32768    // if we can, collect 16K of data at a time        
  76.  
  77. // defines for gFlags bits
  78. #define OTActiveFlag        0
  79. #define    dumpAllPktsFlag        1
  80. #define BufsInitdFlag        4
  81. #define InBackGndFlag        5
  82. #define BuffsHeldFlag        6
  83. #define CheckOptFlag        7
  84. #define StatusBusyFlag        8
  85. #define StatusIdleFlag        9
  86.  
  87. // flags macros for setting, testing and clearing the gFlag bits
  88. #define SetOTActiveFlag(flags)        ((flags) |= 1 << OTActiveFlag)
  89. #define ClrOTActiveFlag(flags)        ((flags) &= (-1 ^ (1 << OTActiveFlag)))
  90. #define TstOTActiveFlag(flags)        (((flags) & (1 << OTActiveFlag)) != 0)
  91.  
  92. #define SetdumpAllPktsFlag(flags)    ((flags) |= 1 << dumpAllPktsFlag)
  93. #define ClrdumpAllPktsFlag(flags)    ((flags) &= (-1 ^ (1 << dumpAllPktsFlag)))
  94. #define TstdumpAllPktsFlag(flags)    (((flags) & (1 << dumpAllPktsFlag)) != 0)
  95.  
  96. #define SetBufsInitdFlag(flags)        ((flags) |= 1 << BufsInitdFlag)
  97. #define ClrBufsInitdFlag(flags)        ((flags) &= (-1 ^ (1 << BufsInitdFlag)))
  98. #define TstBufsInitdFlag(flags)        (((flags) & (1 << BufsInitdFlag)) != 0)
  99.  
  100. #define SetInBackGndFlag(flags)        ((flags) |= 1 << InBackGndFlag)
  101. #define ClrInBackGndFlag(flags)        ((flags) &= (-1 ^ (1 << InBackGndFlag)))
  102. #define TstInBackGndFlag(flags)        (((flags) & (1 << InBackGndFlag)) != 0)
  103.  
  104. #define SetBuffsHeldFlag(flags)        ((flags) |= 1 << BuffsHeldFlag)
  105. #define ClrBuffsHeldFlag(flags)        ((flags) &= (-1 ^ (1 << BuffsHeldFlag)))
  106. #define TstBuffsHeldFlag(flags)        (((flags) & (1 << BuffsHeldFlag)) != 0)
  107.  
  108. #define SetCheckOptFlag(flags)        ((flags) |= 1 << CheckOptFlag)
  109. #define ClrCheckOptFlag(flags)        ((flags) &= (-1 ^ (1 << CheckOptFlag)))
  110. #define TstCheckOptFlag(flags)        (((flags) & (1 << CheckOptFlag)) != 0)
  111.  
  112. #define SetStatusBusyFlag(flags)    ((flags) |= 1 << StatusBusyFlag)
  113. #define ClrStatusBusyFlag(flags)    ((flags) &= (-1 ^ (1 << StatusBusyFlag)))
  114. #define TstStatusBusyFlag(flags)    (((flags) & (1 << StatusBusyFlag)) != 0)
  115.  
  116. #define SetStatusIdleFlag(flags)    ((flags) |= 1 << StatusIdleFlag)
  117. #define ClrStatusIdleFlag(flags)    ((flags) &= (-1 ^ (1 << StatusIdleFlag)))
  118. #define TstStatusIdleFlag(flags)    (((flags) & (1 << StatusIdleFlag)) != 0)
  119.  
  120. // defines for the semaphore bits
  121. #define kInListenLoop        0        // this bit used with OTAtomicSetBit to control re-entrancy into the DoListenAccept procedure
  122. #define kInRcvDataFlag        1        // used with OTAtomic calls to check whether in DoReceive call
  123.  
  124. // defines for flags bits
  125. #define EPActiveFlag        0        // indicates that the endpoint is active
  126. #define EPBoundFlag            1        // indicates the endpoint is bound
  127. #define EPBusyFlag            2        // used with handoff endpoint to indicate it has accepted 
  128.                                     // a handoff endpoint
  129. #define PassconFlag            3        // the passive connection has completed
  130. #define ListenPendFlag        4
  131. #define AcceptPendFlag        5
  132. #define UnbindPendFlag        7        // indicates that the endpoint is pending an unbind request to
  133.                                     // to complete
  134. #define DisconPendFlag        8        // indicates that a disconnect request is pending
  135. #define ForceCloseFlag        9        // indicates that we want to force the CloseProvider and and re-open
  136.                                     // the endpoint
  137. #define OpenPendFlag        10        // indicates that we are awaiting a OpenComplete event
  138. #define EOMOnFlag            11        // EOM option enabled
  139. #define    TempFileFlag        12        // indicates that a temp file has been opened for data to this endpoint
  140. #define InPSQueryFlag        13        // indicates that the endpoint is currently processing a PS query
  141. #define HasDataFlag            14        // indicates that there is more to read for this endpoint
  142. #define FirstPktFlag        15        // indicates that we are looking for the first packet to set time in value
  143. #define DumpPktsFlag        16        // indicates that for this endpoint we will dump all packets
  144.  
  145. // flags macros for setting, testing and clearing the flag bits
  146. #define SetEPActiveFlag(flags)        ((flags) |= 1 << EPActiveFlag)
  147. #define ClrEPActiveFlag(flags)        ((flags) &= (-1 ^ (1 << EPActiveFlag)))
  148. #define TstEPActiveFlag(flags)        (((flags) & (1 << EPActiveFlag)) != 0)
  149.  
  150. #define SetEPBoundFlag(flags)        ((flags) |= 1 << EPBoundFlag)
  151. #define ClrEPBoundFlag(flags)        ((flags) &= (-1 ^ (1 << EPBoundFlag)))
  152. #define TstEPBoundFlag(flags)        (((flags) & (1 << EPBoundFlag)) != 0)
  153.  
  154. #define SetEPBusyFlag(flags)        ((flags) |= 1 << EPBusyFlag)
  155. #define ClrEPBusyFlag(flags)        ((flags) &= (-1 ^ (1 << EPBusyFlag)))
  156. #define TstEPBusyFlag(flags)        (((flags) & (1 << EPBusyFlag)) != 0)
  157.  
  158. #define SetPassconFlag(flags)        ((flags) |= 1 << PassconFlag)
  159. #define ClrPassconFlag(flags)        ((flags) &= (-1 ^ (1 << PassconFlag)))
  160. #define TstPassconFlag(flags)        (((flags) & (1 << PassconFlag)) != 0)
  161.  
  162. #define SetListenPendFlag(flags)    ((flags) |= 1 << ListenPendFlag)
  163. #define ClrListenPendFlag(flags)    ((flags) &= (-1 ^ (1 << ListenPendFlag)))
  164. #define TstListenPendFlag(flags)    (((flags) & (1 << ListenPendFlag)) != 0)
  165.  
  166. #define SetAcceptPendFlag(flags)    ((flags) |= 1 << AcceptPendFlag)
  167. #define ClrAcceptPendFlag(flags)    ((flags) &= (-1 ^ (1 << AcceptPendFlag)))
  168. #define TstAcceptPendFlag(flags)    (((flags) & (1 << AcceptPendFlag)) != 0)
  169.  
  170. #define SetUnbindPendFlag(flags)    ((flags) |= 1 << UnbindPendFlag)
  171. #define ClrUnbindPendFlag(flags)    ((flags) &= (-1 ^ (1 << UnbindPendFlag)))
  172. #define TstUnbindPendFlag(flags)    (((flags) & (1 << UnbindPendFlag)) != 0)
  173.  
  174. #define SetDisconPendFlag(flags)    ((flags) |= 1 << DisconPendFlag)
  175. #define ClrDisconPendFlag(flags)    ((flags) &= (-1 ^ (1 << DisconPendFlag)))
  176. #define TstDisconPendFlag(flags)    (((flags) & (1 << DisconPendFlag)) != 0)
  177.  
  178. #define SetForceCloseFlag(flags)    ((flags) |= 1 << ForceCloseFlag)
  179. #define ClrForceCloseFlag(flags)    ((flags) &= (-1 ^ (1 << ForceCloseFlag)))
  180. #define TstForceCloseFlag(flags)    (((flags) & (1 << ForceCloseFlag)) != 0)
  181.  
  182. #define SetOpenPendFlag(flags)        ((flags) |= 1 << OpenPendFlag)
  183. #define ClrOpenPendFlag(flags)        ((flags) &= (-1 ^ (1 << OpenPendFlag)))
  184. #define TstOpenPendFlag(flags)        (((flags) & (1 << OpenPendFlag)) != 0)
  185.  
  186. #define SetEOMOnFlag(flags)            ((flags) |= 1 << EOMOnFlag)
  187. #define ClrEOMOnFlag(flags)            ((flags) &= (-1 ^ (1 << EOMOnFlag)))
  188. #define TstEOMOnFlag(flags)            (((flags) & (1 << EOMOnFlag)) != 0)
  189.  
  190. #define SetTempFileFlag(flags)        ((flags) |= 1 << TempFileFlag)
  191. #define ClrTempFileFlag(flags)        ((flags) &= (-1 ^ (1 << TempFileFlag)))
  192. #define TstTempFileFlag(flags)        (((flags) & (1 << TempFileFlag)) != 0)
  193.  
  194. #define SetInPSQueryFlag(flags)        ((flags) |= 1 << InPSQueryFlag)
  195. #define ClrInPSQueryFlag(flags)        ((flags) &= (-1 ^ (1 << InPSQueryFlag)))
  196. #define TstInPSQueryFlag(flags)        (((flags) & (1 << InPSQueryFlag)) != 0)
  197.  
  198. #define SetHasDataFlag(flags)        ((flags) |= 1 << HasDataFlag)
  199. #define ClrHasDataFlag(flags)        ((flags) &= (-1 ^ (1 << HasDataFlag)))
  200. #define TstHasDataFlag(flags)        (((flags) & (1 << HasDataFlag)) != 0)
  201.  
  202. #define SetFirstPktFlag(flags)        ((flags) |= 1 << FirstPktFlag)
  203. #define ClrFirstPktFlag(flags)        ((flags) &= (-1 ^ (1 << FirstPktFlag)))
  204. #define TstFirstPktFlag(flags)        (((flags) & (1 << FirstPktFlag)) != 0)
  205.  
  206. #define SetDumpPktsFlag(flags)        ((flags) |= 1 << DumpPktsFlag)
  207. #define ClrDumpPktsFlag(flags)        ((flags) &= (-1 ^ (1 << DumpPktsFlag)))
  208. #define TstDumpPktsFlag(flags)        (((flags) & (1 << DumpPktsFlag)) != 0)
  209.  
  210.  
  211. enum {
  212.     kLookingForEndStr = 1,
  213.     kLookingForQueryStr,
  214.     kLookingForDefaultResponse,
  215.     kLookingForEOFStr
  216. };
  217.  
  218. enum {
  219.     kSetBusyStr = 1,
  220.     kSetIdleStr,
  221.     kAcceptOption,
  222.     kDeclineOption,
  223.     kQuitTest
  224. };    
  225.  
  226.  
  227. /*******************************************************************************
  228. ** Structures
  229. ********************************************************************************/
  230. typedef struct MyEndpointRef MyEndpointRef;
  231.  
  232. typedef struct 
  233. {
  234.         OTLink        fLink;                        // first field standard for OTLink list
  235.         OTFlags        flags;
  236.         MyEndpointRef *theEp;                    // save the endpoint ref associated with the endpoint
  237.         UInt32        lastPos;                    // last scanned position in the buffer
  238.         UInt32        numBytes;                    // numBytes in this packet
  239.         OTTimeStamp    timeStamp;                    // timestamp of this packet
  240.         UInt8        data[kPAPDataSize];            // data bytes of packet
  241. } PacketBuffer;
  242.  
  243. typedef PacketBuffer *PacketPtr;
  244.  
  245. struct MyEndpointRef
  246. {
  247.     EndpointRef        ep;
  248.     UInt32            flags;
  249.     OTLIFO            *usedQ;                    // ptr to incoming packet queue for this connection
  250.     PacketPtr        prevPtr;                // used while processing a postscript
  251.                                             // query where we have to save the previous packet
  252.                                             // in order to complete processing of queries.
  253.     OTTimeStamp        timeDataIn;                // timestamp of first incoming packet
  254.     OTTimeStamp     timeDataEnd;            // timestamp of last incoming packet
  255.     OTTimeStamp        timerDog;                // timestamp of most recent packet
  256.  
  257.     UInt32            numBytesIn;                // number of bytes received for a connection
  258.     UInt16            psState;                // state while processing a postscript query
  259.     short            fRefNum;                // file ref num of temp file associated
  260.                                             //    with this endpoint
  261.     UInt8            semaphore;
  262.     UInt8            dummy;
  263. };
  264.  
  265.  
  266. // Prototypes
  267. extern void DoValueBreak(long value, const char* message);
  268.  
  269.  
  270. #if PRAGMA_IMPORT_SUPPORTED
  271. #pragma import off
  272. #endif
  273.  
  274. #if PRAGMA_ALIGN_SUPPORTED
  275. #pragma options align=reset
  276. #endif
  277.  
  278. #ifdef __cplusplus
  279. }
  280. #endif
  281.  
  282. #endif /* __PAPSERVERSAMPLE__ */
  283.